package org.rcgwt.client.ui.validator.impl;

import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.IConverter;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.IValidatorElement;

import com.google.gwt.user.client.ui.Widget;

/**
 * A typed Integer Converter. It can return a object representation of a string.
 * 
 * @author Elian ORIOU
 * 
 */

public class IntegerConverter implements IConverter<Integer>, ISingleton {

	private static IntegerConverter INSTANCE = new IntegerConverter();

	protected IntegerConverter() {
	}

	@Override
	public Integer getAsObject(IClientValidatorContext context,
			Widget component, String value) {
		return Integer.valueOf(value);
	}

	@Override
	public String getAsString(IClientValidatorContext context,
			Widget component, Integer value) {
		return value.toString();
	}

	public static IValidatorElement getInstance() {
		return INSTANCE;
	}

}
